package com.luych.toolbox.common.feign.intf.gateway.center;

import com.luych.toolbox.common.feign.view.gateway.center.FileView;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@FeignClient(contextId = "gateway-center-file", name = "gateway-center", path = "/api/file", decode404 = true)
public interface FileFeign {

    @ApiOperation("上传一个新的文件")
    @ApiResponses({@ApiResponse(code = 200, message = "上传成功，返回文件UUID")})
    @PostMapping()
    String post(@ApiParam(value = "二进制流") @RequestParam("multipartFile") MultipartFile multipartFile,
                @ApiParam(value = "文件名") @RequestParam(name = "name", required = false) String name);

    @ApiOperation("获取一个文件")
    @ApiResponses({@ApiResponse(code = 200, message = "获取成功，返回文件二进制流")})
    @GetMapping("/{uuid}/get")
    Resource get(@ApiParam(value = "文件UUID") @PathVariable("uuid") String uuid);

    @ApiOperation("修改一个文件")
    @ApiResponses({@ApiResponse(code = 200, message = "修改成功")})
    @PutMapping("/{uuid}")
    void put(@ApiParam(value = "文件UUID") @PathVariable("uuid") String uuid,
             @ApiParam(value = "二进制流") MultipartFile multipartFile);

    @ApiOperation("删除一个文件")
    @ApiResponses({@ApiResponse(code = 200, message = "删除成功")})
    @DeleteMapping("/{uuid}")
    void delete(@ApiParam(value = "文件UUID") @PathVariable("uuid") String uuid);

    @ApiOperation("确认一个文件")
    @ApiResponses({@ApiResponse(code = 200, message = "确认成功")})
    @PostMapping("/{uuid}/confirm")
    void confirm(@ApiParam(value = "文件UUID") @PathVariable("uuid") String uuid);

    @ApiOperation("获取文件列表")
    @ApiResponses({@ApiResponse(code = 200, message = "获取成功，返回文件文件列表")})
    @GetMapping()
    List<FileView> list();

}
